package com.myidis.servlet;

import com.auxiliary.SignalThresholdCalculator;
import com.auxiliary.TimeSequence;
import com.myidis.entity.*;
import com.myidis.mapper.QuotaDataMapper;
import com.myidis.mapper.QuotaMapper;
import com.myidis.mapper.SignalQuotaManagementMapper;
import com.myidis.mapper.SubjectAnalyticMapper;
import com.myidis.request.SearchReq;
import com.myidis.request.SignalReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class SignalQuotaManagementServlet {
    @Autowired
    SignalQuotaManagementMapper signalQuotaManagementMapper;
    @Autowired
    SubjectAnalyticMapper subjectAnalyticMapper;
    @Autowired
    QuotaDataMapper quotaDataMapper;
    @Autowired
    QuotaMapper quotaMapper;


    public ArrayList<AnalysisTheme> findSubject() {
        return subjectAnalyticMapper.allName();
    }


    public ArrayList<SignalQuota> subjectQuotaList(String sea) {
        ArrayList<SignalQuota> a = signalQuotaManagementMapper.getBySubject(sea);
        for (SignalQuota e : a){
            System.out.println(e.getQuota());
            e.setQuota(quotaMapper.getOne(Integer.parseInt(e.getQuota())).getChineseName());
        }
        return a;
    }

    public ArrayList<SignalQuota> combinationQuotaList(String sea) {
        ArrayList<SignalQuota> a = signalQuotaManagementMapper.getByCombination(sea);
        for (SignalQuota e : a){
            System.out.println(e.getQuota());
            e.setQuota(quotaMapper.getOne(Integer.parseInt(e.getQuota())).getChineseName());
        }
        return a;
    }


    public int addToCombination(SignalQuota add){
      return signalQuotaManagementMapper.addToCombination(add);
    }

    public int addToSubject(SignalQuota add){
        return signalQuotaManagementMapper.addToSubject(add);
    }

    public int addCombination(IndexCombination add){
        return signalQuotaManagementMapper.addCombination(add);
    }

    public SignalThreshold detail(SearchReq sea) {
        return signalQuotaManagementMapper.getThreshold(sea);
    }

    public SignalThreshold calculateThreshold (SignalReq sea) {
//        TimeSequence ts = new TimeSequence(quotaDataMapper.getByQuota(sea.getQuota(),sea.getStartTime(), sea.getEndTime()));
//        SignalThresholdCalculator threshold = new SignalThresholdCalculator();
//        SignalThreshold result = threshold.CalculateThresholdByStatistics(ts, sea.getThresholdPercentList(), sea.getQuota(), sea.getSubject());
//        return result;
        return null;
     }

    public int saveThreshold(SignalThreshold signalThreshold) {
        return signalQuotaManagementMapper.addThreshold(signalThreshold);
    }

    public int delectCombination(int id) {
        return signalQuotaManagementMapper.delectCombination(id);
    }

    public int delectInCombination(int id) {
        return signalQuotaManagementMapper.delectInCombination(id);
    }

    public int delectInSubject(int id) {
        return signalQuotaManagementMapper.delectInSubject(id);
    }

    public ArrayList<IndexCombination> combination() {
        return signalQuotaManagementMapper.combinationlist();
    }
}
